;
(function () {
  var CONTRACTID = hlUrlUtil.GetQueryString('aid');
  var ACCOUNTID = hlUrlUtil.GetQueryString('id');
  var href = hlUrlUtil.GetQueryString('page');

  Array.prototype.removeRepeatBuildingAndFLoor = function () {
    var res = [this[0]];
    for (var i = 1; i < this.length; i++) {
      var repeat = false;
      for (var j = 0; j < res.length; j++) {
        if (this[i].buildingName == res[j].buildingName && this[i].floorNum == res[j].floorNum) {
          repeat = true;
        }
      }
      if (!repeat) {
        res.push(this[i]);
      }
    }
    return res;
  };

  new Vue({
    el: '#bill-edit',
    data: {
      idA: {
        ida: ACCOUNTID,
        idb: CONTRACTID
      },
      href: href,
      contractData: {
        ot: [],
        st: []
      },
      billData: {
        transactions: [],
        expenses: [],
        invoiceInfos: [],
        carryOverInfos: []
      },
      memo: {
        content: '',
        flag: false
      },
      payfn: [{
          name: '现金支付',
          code: 'XJ'
        },
        {
          name: '银行转账',
          code: 'BK'
        },
				{
				  name: '银行汇票',
				  code: 'BD'
				},
				{
				  name: '银行本票',
				  code: 'BN'
				},
				{
				  name: '信用卡',
				  code: 'CC'
				},
        {
          name: '支票',
          code: 'ZP'
        },
        {
          name: '支付宝',
          code: 'AP'
        },
        {
          name: '微信',
          code: 'WX'
        },
        {
          name: '其他',
          code: 'ET'
        }
      ],
      txs: [{
        "amountTPay": "", //收款金额
        "lateFeeTPay": "", //实收滞纳金
        "payment_way": "", //支付方式
        "payment_time": "", //支付时间
        "payment_no": "", //支付单号
        "memo": "", //说明
        "vouchers": [],//支付凭证，逗号分割
				"receiptAccount": []
      }],
      closeFlag: false,
      imgsArr: [{
        url: []
      }],
      index: 0,
      st: [], // 车位
      wp: [], // 工位
      stTotalNum: 0, // 车位总数
      wpTotalNum: 0, // 工位总数
      totalArea: 0, // 单元总面积
      building: [], // 楼宇信息
      projectName: null, // 项目名
      unitOpenFlag: false,
      wpOpenFlag: false,
      stOpenFlag: false,
      totalNum: 0, // 计算本次应收总金额次数,
      invoiceInfos: [],
      invoicetype: [],
      permissions: JSON.parse(window.localStorage.getItem('permissions')),
      projectId: '',
      editFlag: true,
      logData: [],
      CZOpenFlag: false,
      showEnlargeArr:[],
      isMustInvoice:false,
      messageFlag:false,
      errormsgShow:false,
      rentTaxFee:'',
      projectIds: null,
      expenseList: [],
    },
    filters: {
      timestamp: function (time) {
        if (!time) return '--'
        return hlDateUtil.formatUTCDate(time, 'yyyy-MM-dd')
      },
      billState: function (state) {
        if (!state) return '';
        return hlCodeConvert.billPaymentState(state)
      },
      toFixed2: function (n) {
        return Number(n).toFixed(2)
      },
      billPayWay: function (state) {
        return hlCodeConvert.billPayWay(state)
      },
      payfn: function (str) {
        var result = '';
        switch (str) {
          case 'XJ':
            result = '现金支付'
            break;
          case 'BK':
            result = '银行转账'
            break;
					case 'BD':
					  result = '银行汇票'
					  break;
					case 'BN':
					  result = '银行本票'
					  break;
					case 'CC':
					  result = '信用卡'
					  break;
          case 'ZP':
            result = '支票'
            break;
          case 'AP':
            result = '支付宝'
            break;
          case 'WX':
            result = '微信'
            break;
          case 'ET':
            result = '其他'
            break;
        }
        return result
      },
      //千分位
      formatNum: function (n) {
        return hlNumberUtil.formatNum(n)
      },
      absNum: function (n) {
        return Math.abs(n)
      }
    },
    computed: {
      temporarys: function () {
        var result = 0;
        for (var i = 0; i < this.billData.expenses.length; i++) {
          if (this.billData.expenses[i].expenseType === 'T') {
            result++
          }
        }
        return result
      },
      //应收本金
      totalYS: function () {
        var result = 0; //总和
        var IS = 0; //已收款
        this.billData.expenses.map(function (item) {
          if (Number(item.amountReceived) > 0) {
            result += Number(item.amountReceived)
          }
        })
        return result
      },
      //已收本金
      totalIS: function () {
        var result = 0; //总和
        this.billData.expenses.map(function (item) {
          result += Number(item.amountPayed);
        })
        return result
      },
      //减免本金
      totalJM: function () {
        var result = 0; //总和
        this.billData.expenses.map(function (item) {
          result += Number(item.amountDerate);
        })
        return result
      },
      //结转抵扣 (应收)
      carryOverTotalAmount: function () {
        var result = 0; //总和
        this.billData.expenses.map(function (item) {
          if (item.carryOverTotalAmount > 0 && item.amountReceived > 0) {
            result += Number(item.carryOverTotalAmount);
          }
        })
        return result
      },
      //本次应收本金
      totalBCYS: function () {
        var result = 0; //总和
        result = this.totalYS - this.totalIS - this.totalJM - this.carryOverTotalAmount;
        return result
      },
      //本次应收滞纳金
      totalYSznj: function () {
        var result = 0; //总和
        var IS = 0; //已收款
        this.billData.expenses.map(function (item) {
          result += Number(item.lateFeeReceived)
        })
        return result
      },
      //已收滞纳金
      totalISznj: function () {
        var result = 0; //总和
        this.billData.expenses.map(function (item) {
          result += Number(item.lateFeePayed);
        })
        return result
      },
      //减免滞纳金
      totalJMznj: function () {
        var result = 0; //总和
        this.billData.expenses.map(function (item) {
          result += Number(item.lateFeeDerate);
        })
        return result
      },
      //本次应收滞纳金
      totalBCYSznj: function () {
        var result = 0; //总和
        // result = this.totalYSznj - this.totalISznj - this.totalJMznj;
        this.billData.expenses.map(function (item) {
          result += Number(item.lateFeeTPay)
        })
        return result
      },
      //本次应退
      totalYT: function () {
        var result = 0; //总和
        this.billData.expenses.map(function (item) {
          result += Math.abs(Number(item.amountRefund))
        })
        return result
      },
      //已退本金
      totalIT: function () {
        var result = 0; //总和
        this.billData.expenses.map(function (item) {
          result += Math.abs(Number(item.refundPayed))
        })
        return result
      },
      //结转抵扣 (应退)
      carryOverTotalAmountYt: function () {
        var result = 0; //总和
        this.billData.expenses.map(function (item) {
          if (item.carryOverTotalAmount > 0 && item.amountRefund > 0) {
            result += Number(item.carryOverTotalAmount);
          }
        })
        return result
      },
      //本次应退
      totalBCYT: function () {
        var result = 0; //总和
        result = this.totalYT - this.totalIT - this.carryOverTotalAmountYt
        return result
      },
      //本次应收合计
      total: function () {
        var result = 0; //总和
        result = this.totalBCYS + this.totalBCYSznj - this.totalBCYT;
        console.log(result)
        if (this.totalNum == 1) {
          this.txs[0]['amountTPay'] = (this.totalBCYS - this.totalBCYT).toFixed(2);
          this.txs[0]['lateFeeTPay'] = this.totalBCYSznj.toFixed(2);
        }
        this.totalNum++;
        return Number(result).toFixed(2)
      },

      cumulation: function () {
        var result = 0;
        this.txs.map(function (item) {
          result += Number(hlNumberUtil.formatThousandsNum(item.amountTPay)) + Number(hlNumberUtil.formatThousandsNum(item.lateFeeTPay))
        })
        return Number(result).toFixed(2);
      },

    },
    methods: {
      // 录入滞纳金、应收滞纳金
      computedZNJ(val, index, str) {
        if (val < 0) {
          if (str == 'lateFeeTPay') {
            hl.toast('滞纳金必须大于0')
            this.billData.expenses[index].lateFeeTPay = 0
          } else {
            hl.toast('减免滞纳金必须大于0')
            this.billData.expenses[index].lateFeeDerate = 0
          }
        }
      },
      // 获取财务配置是否增加发票项目设置
      getInitInvoice(){
        hlhttp.get({
          url: 'configure/dict',
          data: {
            module_code: 'CIWU',
            config_name: 'CW_INVOCATION_REQURIED_CONFIG',
          },
          success: (res) => {
            this.isMustInvoice = res[0].dictValue=='N'?false:true;
            // 如果财务配置开启状态 那么默认展开一项费用结算
            if(this.isMustInvoice){
              this.newAddinvoice()
            }
          }
        })
      },
      checkoutMoney(item){
        item.invoice_out_amount = (item.invoice_out_amount*1).toFixed(2)
        // 税金=金额/（1+税率）*税率
        item.tax_amount = (item.invoice_out_amount/(1+this.rentTaxFee/100)*this.rentTaxFee/100).toFixed(2)
        // 不含税金额=金额 - 税金
        item.tax_free = (item.invoice_out_amount - item.tax_amount).toFixed(2)
        if(this.isMustInvoice && item.invoice_out_amount && item.tax_amount && item.tax_free){
          if(Number(item.invoice_out_amount).toFixed(2) != (Number(item.tax_amount) + Number(item.tax_free)).toFixed(2)){
            this.messageFlag = true
          }
        }
      },
      checkoutMoneySelf(item){
        if(this.isMustInvoice && item.invoice_out_amount && item.tax_amount && item.tax_free){
          if(Number(item.invoice_out_amount).toFixed(2) != (Number(item.tax_amount) + Number(item.tax_free)).toFixed(2)){
            this.messageFlag = true
          }
        }
      },
      closeErrormsg(){
        this.errormsgShow = false
      },
      //获取日志详情
      getlogData() {
        var that = this
        hlhttp.get({
          url: 'bill/logs',
          data: {
            bill_id: ACCOUNTID
          },
          success: function (data) {
            that.logData = data.groupLogs
            that.logData.forEach(item => {
              if (item.operationName == '编辑账单费项') {
                item.logRecords.forEach(item1 => {
                  item1.list = []
                  for (var i = 0; i < item1.rowData.length; i += 3) {
                    item1.list.push(item1.rowData.slice(i, i + 3));
                  }
                })
              }
            })
          }
        })
      },
      //是否改变
      changeBill(i, type) {
        console.log(i, type)
        if (this.billData.expenses[i][type] == 'N') {
          this.billData.expenses[i][type] = 'Y'
        }
      },
      //编辑保存
      editSave: function () {
        this.editFlag = !this.editFlag;
        if (this.editFlag) {
          let expense_info = [];
          for (var i = 0; i < this.billData.expenses.length; i++) {
            item = this.billData.expenses[i];
            if (item.paymentState !== 'APE') {
              expense_info.push({
                expense_id: item.id,
                derate_expense: item.amountDerate,
                derate_late_fee: item.lateFeeDerate,
                // late_fee_received: item.lateFeeReceived,
                late_fee_tpay: item.lateFeeTPay,
                derate_expense_update_flag: item.derate_expense_update_flag == 'Y' ? 'Y' : 'N',
                derate_late_fee_update_flag: item.derate_late_fee_update_flag == 'Y' ? 'Y' : 'N',
                // late_fee_received_update_flag: item.late_fee_received_update_flag == 'Y' ? 'Y' : 'N'
                late_fee_tpay_update_flag: item.lateFeeTPayUpdateFlag == 'Y' ? 'Y' : 'N'
              })
            }
          }

          hlhttp.put({
            baseUrl: _url2,
            url: 'v2/bill',
            data: {
              bill_id: ACCOUNTID, //账单ID
              is_submit: 'N',
              expense_info: JSON.stringify(expense_info)
            },
            success: () => {
              hl.toast('账单编辑成功')
              this.getBillData()
              this.getlogData()
              this.closeFlag = false;
            }
          })
        }
      },
      // 获取合同单元信息
      getContractUnitsData: function () {
        var self = this;
        hlhttp.get({
          url: 'contract/units',
          data: {
            id: CONTRACTID
          },
          success: function (data) {

            // 单元
            var buildingData = self.dealWithUnitData(data)
            self.totalArea = buildingData.totalArea
            self.building = buildingData.building
            // 车位
            self.st = [];
            self.wp = [];
            var stTotalNum = 0;
            var wpTotalNum = 0;
            data.map(function (item) {
              if (item.positions && item.unitType === 'ST') {
                stTotalNum = stTotalNum + item.positions.length;
                item['num'] = item.positions.length;
                self.st.push(item)
              }
              if (item.positions && item.unitType === 'WP') {
                wpTotalNum = wpTotalNum + item.positions.length;
                item['num'] = item.positions.length;
                self.wp.push(item)
              }
            })
            self.stTotalNum = stTotalNum;
            self.wpTotalNum = wpTotalNum;
          }
        })
      },
      // 单元数据去重整合处理
      dealWithUnitData: function (unitsData) {
        // 去除含有工位车位的单元
        var units = [];
        unitsData.map(function (_item) {
          if (_item.positions.length === 0) {
            units.push(_item)
          }
        })
        if (units.length === 0) {
          return {
            building: [],
            totalArea: 0
          }
        }
        // 合并单元项
        var unit = [];
        var totalArea = 0;
        for (var i = 0; i < units.length; i++) {
          unit.push({
            buildingName: units[i].buildingName,
            floorNum: units[i].floorNum,
            floorName: units[i].floorName,
            unit: []
          })
        }
        var unitArr = unit.removeRepeatBuildingAndFLoor()
        for (var z = 0; z < unitArr.length; z++) {
          for (var m = 0; m < units.length; m++) {
            if (units[m].buildingName == unitArr[z].buildingName && units[m].floorNum == unitArr[z].floorNum) {
              unitArr[z].unit.push(units[m].unitName + '(' + hlNumberUtil.formatNum(units[m].unitAcreage) + 'm²)')
              totalArea = totalArea + Number(units[m].unitAcreage)
            }
          }
        }
        // 合并楼层项
        var building = [];
        for (var j = 0; j < unitArr.length; j++) {
          building.push({
            buildingName: unitArr[j].buildingName,
            floor: []
          })
        }
        var buildingArr = hlArrayUtil.removeRepeat(building, 'buildingName')
        for (var k = 0; k < buildingArr.length; k++) {
          for (var n = 0; n < unitArr.length; n++) {
            if (unitArr[n].buildingName == buildingArr[k].buildingName) {
              buildingArr[k].floor.push({
                'floorNum': unitArr[n].floorNum,
                'floorName': unitArr[n].floorName,
                'unit': unitArr[n].unit
              })
            }
          }
        }
        return {
          building: buildingArr,
          totalArea: totalArea
        }
      },
      // 查看出租资源详情信息
      checkDetailMes: function (type) {
        var self = this;
        if (type === 'unit') {
          if (self.unitOpenFlag === true) {
            self.unitOpenFlag = false
            return false
          }
          if (self.unitOpenFlag === false) {
            self.unitOpenFlag = true
            return false
          }
        }
        if (type === 'wp') {
          if (self.wpOpenFlag === true) {
            self.wpOpenFlag = false;
            return false;
          }
          if (self.wpOpenFlag === false) {
            self.wpOpenFlag = true
            return false;
          }
        }
        if (type === 'st') {
          if (self.stOpenFlag === true) {
            self.stOpenFlag = false
            return false;
          }
          if (self.stOpenFlag === false) {
            self.stOpenFlag = true
            return false;
          }
        }
      },
      getContractData: function () {
        var _this = this;
        contract.formatUnitData(CONTRACTID, function (data) {
          _this.contractData = data;
        })
      },
      getBillData: function () {
        var _this = this;
        hlhttp.get({
          url: 'bill,expenses,transactions',
          data: {
            bill_id: ACCOUNTID
          },
          success: function (data) {
            //项目ID
            _this.projectId = data.projectId
            _this.rentTaxFee = data.rentTaxFee
            data.expenses.map(item => {
              item.derate_expense_update_flag = item.derateExpenseUpdateFlag && item.derateExpenseUpdateFlag == 'Y' ? 'Y' : 'N';
              item.derate_late_fee_update_flag = item.derateLateFeeUpdateFlag && item.derateLateFeeUpdateFlag == 'Y' ? 'Y' : 'N';
              item.late_fee_received_update_flag = item.lateFeeReceivedUpdateFlag && item.lateFeeReceivedUpdateFlag == 'Y' ? 'Y' : 'N';
              item.expense_name_update_flag = item.nameUpdateFlag && item.nameUpdateFlag == 'Y' ? 'Y' : 'N';
              item.expense_amount_update_flag = item.amountReceiveUpdateFlag && item.amountReceiveUpdateFlag == 'Y' ? 'Y' : 'N';
              item.expense_memo_update_flag = item.memoUpdateFlag && item.memoUpdateFlag == 'Y' ? 'Y' : 'N';
              item.lateFeeTPayUpdateFlag = item.lateFeeTPayUpdateFlag && item.lateFeeTPayUpdateFlag == 'Y' ? 'Y' : 'N';
            })

						if (data.receiptAccountList) {
							data.receiptAccountList.map(item => {
								item.name = item.accountName+' ('+item.bankAccount+')'
								item.code = item.accountCode
							})
							_this.txs[0].receiptAccount = data.receiptAccountList.length ? [data.receiptAccountList[0].code] : []
						}

            data.expenses = hlArrayUtil.replaceData(data.expenses, [{key: 'id', rKey: 'code'}]);
            _this.billData = data

            if (data.intentId) {
              _this.getYxInfo(data.intentId)
            }


          }
        })
      },
      getMemo: function (content, flag) {
        this.memo = {
          content: content,
          flag: flag
        }
      },
      //大图浏览
      getBigPic: function (img) {
        var temp = img ? img.split(',') : null;
        $.imageShow(temp)
      },
      validateReceivedMoney: function (val, index) {
        if (!hlNumberUtil.isNum(hlNumberUtil.formatThousandsNum(val))) {
          $($('.received-money')[index]).val('')
          $($('.received-money')[index]).focus()
          hl.toast('请输入数字')
          this.txs[index].amountTPay = ''
          return false;
        }
      },
      mouseOver(index){
        this.$set(this.showEnlargeArr,index,this.imgsArr[0].url[index])

      },
      mouseLeave(index){
        this.$set(this.showEnlargeArr,index,'')
      },
      previewImage: function (url) {
        var imageExt = ['jpg', 'jpeg', 'png', 'JPG', 'JPEG', 'PNG'];
        var pdfExt = ['pdf', 'PDF'];
        var officeExt = ['docx', 'doc', 'xlsx', 'xls', 'xlt']
        var imageFlag = false;
        var pdfFlag = false;
        var officeFlag = false;

        imageExt.forEach((e, i) => {
          if (url.indexOf(e) !== -1) imageFlag = true;
        })

        if (imageFlag) {
          $.imageShow([url])
          return
        }
        pdfExt.forEach((e, i) => {
          if (url.indexOf(e) !== -1) pdfFlag = true;
        })
        if (pdfFlag) {
          $.previewPDF(url)
          return
        }

        officeExt.forEach((e, i) => {
          if (url.indexOf(e) !== -1) officeFlag = true
        })
        if (officeFlag) {
          $.previewOffice(url)
          return
        }
        hl.toast('暂不支持该格式')
      },
      //确认收款
      submitBill: function () {
        let msgerr;
        let invoiveflag = false;
        let invoiceArr = this.invoiceInfos
        // 验证开票金额和实收金额是否相等
        let sum = 0
        invoiceArr.forEach(item=>{
          sum+=item.invoice_out_amount*1
        })

        let myonlyflag = invoiceArr.every(item=>{
          return Number(item.invoice_out_amount).toFixed(2) == (Number(item.tax_amount) + Number(item.tax_free)).toFixed(2)
        })
        if(this.isMustInvoice){
          if((this.total!=sum) || !(myonlyflag)){
            this.errormsgShow = true
            return
          }
        }

        if (invoiceArr.length > 0) {
          for (let i = 0; i < invoiceArr.length; i++) {
            let item = invoiceArr[i];
            if (!item.invoice_out_amount.length) {
              msgerr = '开票金额不能为空'
              invoiveflag = true
              break
            }
            if (isNaN(item.invoice_out_amount)) {
              msgerr = '开票金额为数字'
              invoiveflag = true
              break
            }
            if (!item.invoice_no.length) {
              msgerr = '发票号码不能为空'
              invoiveflag = true
              break
            }
          }
          if (invoiveflag) {
            hl.toast(msgerr)
            return
          }

        }

        if (Number(this.total) > 0) {
          if (Number(this.cumulation) > Number(this.total)) {
            hl.toast('本次实收不能大于本次应收，请确认填写金额')
            return false;
          }
        }
        if (Number(this.total) < 0) {
          if (this.cumulation != this.total) {
            hl.toast('退款（实收金额为负）时需一次性结清')
            return false;
          }
        }


        var flag = false,
          paymsg = '',
          waymsg = '',
          timemsg = '',
          date = new Date(),
          btimemsg = '';
        date = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();

        for (var i = 0; i < this.txs.length; i++) {
          this.txs[i].vouchers = this.txs[i].vouchers.toString();
          this.txs[i].amountTPay = hlNumberUtil.formatThousandsNum(this.txs[i].amountTPay).trim()
          if (!this.txs[i].amountTPay) {
            paymsg = '请填写本次实收金额';
            flag = true;
          }
          if (!this.txs[i].lateFeeTPay) {
            paymsg = '请填写本次实收滞纳金';
            flag = true;
          }
          if (!this.txs[i].payment_way) {
            waymsg = '请选择支付方式';
            flag = true;
          }
          if (!this.txs[i].payment_time) {
            timemsg = '请选择支付时间';
            flag = true;
          }
          if (!this.txs[i].payment_time) break;
          if (hlDateUtil.shellDate(date) < hlDateUtil.shellDate(this.txs[i].payment_time)) {
            btimemsg = '支付时间不能大于今天时间';
            flag = true;
          }
        }
        if (flag) {
          if (paymsg) {
            hl.toast(paymsg)
            return false
          }
          if (waymsg) {
            hl.toast(waymsg)
            return false
          }
          if (timemsg) {
            hl.toast(timemsg)
            return false
          }
          if (btimemsg) {
            hl.toast(btimemsg)
            return false
          }
          return
        }

        if (Number(this.total) < Number(this.cumulation)) {
          hl.toast('本次实收不能大于本次应收，请确认填写金额')
          return
        }
        this.closeFlag = true;
      },
      submitFp: function () {
        this.closeFlag = false;
      },

      submitQs: function () {
        var _this = this;
        let invoiceinfos = [];
        let url = null
        const page = hlUrlUtil.GetQueryString('page')

        if (this.invoiceInfos.length > 0) {
          this.invoiceInfos.map(item => {
            invoiceinfos.push({
              invoice_no: item.invoice_no || '#',
              invoice_code: item.invoice_code || '#',
              invoice_type: item.invoice_type || '#',
              invoice_out_time: item.invoice_out_time || '#',
              invoice_out_amount: item.invoice_out_amount || '#',
              tax_free: item.tax_free || '#',
              tax_amount: item.tax_amount || '#',
              expenditure_id: item.expenditure_id || '#',
              expense_type: item.expense_type || '#',
              expense_name: item.expense_name || '#',
            })
          })
        }

        if (page == 'financeList') url = 'bill/balance'
        if (page == 'billList') url = 'bill/overview/balance'

				_this.txs.map(item => {
					item.receiptAccount = item.receiptAccount.toString() || '#'
				})

        hlhttp.post({
          url: url,
          data: {
            bill_id: ACCOUNTID,
            project_id: _this.projectId,
            txs: JSON.stringify(_this.txs),
            invoice_infos: JSON.stringify(invoiceinfos) || '#'
          },
          success: function () {
            hl.toast('确认收款成功')
            if (CONTRACTID != 'undefined') {
              _this.getContractData()
            }
            _this.getBillData()
            _this.txs = [{
              "amountTPay": "", //收款金额
              "lateFeeTPay": "", //实收滞纳金
              "payment_way": "", //支付方式
              "payment_time": "", //支付时间
              "payment_no": "", //支付单号
              "memo": "", //说明
              "vouchers": [] //支付凭证，逗号分割
            }]
            _this.invoiceInfos = [];
            _this.closeFlag = false;
            _this.imgsArr = [{
              url: []
            }]
            document.querySelector('.select-ul span').innerHTML = '请选择支付方式';
          }
        })


      },
      //上传支付凭证
      uploadImg: function (i) {
        $('.js-trigger-upload').trigger('click')
        this.index = i;
      },
      //新增流水
      addNewWater: function () {
        this.txs.push({
          "amountTPay": "", //收款金额
          "lateFeeTPay": "", //实收滞纳金
          "payment_way": "", //支付方式
          "payment_time": "", //支付时间
          "payment_no": "", //支付单号
          "memo": "", //说明
          "vouchers": [] //支付凭证，逗号分割
        })
        this.imgsArr.push({
          url: []
        })
      },
      //删除流水
      delWater: function (i) {
        this.txs.splice(i, 1)
        this.imgsArr.splice(i, 1)
      },
      //删除图片
      delPic: function (i, n) {
        this.imgsArr[i].url.splice(n, 1)
        this.txs[i].vouchers.splice(n, 1)
      },
      //获取意向详情
      getYxInfo(id) {
        var self = this;
        hlhttp.get({
          url: 'contract/intent',
          data: {
            id: id
          },
          success: (data) => {
            data.projectInfo.units.map(item => {
              item.positions = [];
              item.floorName = item.floorNum
            })
            this.contractData.zlfCompany = data.zlfInfo.zlfName
            this.contractData.projectName = data.projectInfo.projectName
            var buildingData = this.dealWithUnitData(data.projectInfo.units)
            this.totalArea = buildingData.totalArea
            this.building = buildingData.building;
            this.printflag = false;
            this.st = [];
            this.wp = [];
            var stTotalNum = 0;
            var wpTotalNum = 0;
            //车位
            let newStArr = hlArrayUtil.removeRepeat(data.projectInfo.stops, 'unitId'),
              newStIds = [];
            newStArr.map(item => {
              item.floor = item.floorNum;
              item.floorName = item.floorNum
              item.positions = []
            })
            data.projectInfo.stops.map(item => {
              newStIds.push(item.stopId)
              newStArr.map(item1 => {
                if (item.unitId == item1.unitId) {
                  stTotalNum++
                  item1.positions.push({
                    positionName: item.stopName,
                    positionId: item.stopId
                  })
                }
              })
            })
            self.st = newStArr;
            let newWpArr = hlArrayUtil.removeRepeat(data.projectInfo.wps, 'unitId'),
              newWpIds = [];
            newWpArr.map(item => {
              item.floor = item.floorNum
              item.children = []
            })
            data.projectInfo.wps.map(item => {
              newWpIds.push(item.wpId)
              newWpArr.map(item1 => {
                if (item.unitId == item1.unitId) {
                  item1.children.push({
                    positionName: item.wpName,
                    positionId: item.wpId
                  })
                }
              })
            })
            this.wp = newWpArr
            self.stTotalNum = stTotalNum;
            self.wpTotalNum = wpTotalNum;
          }
        })
      },

      //新加发票部分
      //发票类型
      getinvoicetype() {
        hlhttp.get({
          url: 'configure/dict',
          data: {
            module_code: 'CIWU',
            config_name: 'CW_INVOICE_TYPE'
          },
          success: (res) => {
            this.invoicetype = res;
          }
        })
      },
      //新增发票
      newAddinvoice() {
        this.invoiceInfos.push({
          invoice_no: '',
          invoice_code: '',
          invoice_type: '',
          invoice_out_time: '',
          invoice_out_amount: '',
          tax_free: '',
          tips: '发票时间',
          tax_amount: '',
          expenditure_id: [],
          expense_type: '',
          expense_name: '',
          id: [],
        })
      },
      //删除此发票
      delinvoice(i) {
        this.invoiceInfos.splice(i, 1)
      },
      selectExpense(data,i) {
        console.log(data);
        this.invoiceInfos[i]['expense_type'] = data[0]['expenseType']
        this.invoiceInfos[i]['expense_name'] = data[0]['name']
        this.invoiceInfos[i]['expenditure_id'] = data[0]['expenditureId']
      }
    },
    mounted: function () {
      this.getContractUnitsData()
      if (CONTRACTID != 'undefined') {
        this.getContractData()
      }
      this.getBillData()
      this.getinvoicetype()
      this.getlogData()
      this.getInitInvoice()
      hlSelectUi()
      var _this = this;
      uploader('.bill-settlement', '.js-trigger-upload', uploadUrl, function (src) {
        _this.txs[_this.index].vouchers.push(JSON.parse(src.response).url)
        _this.imgsArr[_this.index].url.push(JSON.parse(src.response).url)
      })
    }
  })
}())
